<?php
$parent = isset($CONFIG['parent']) ? (int)$CONFIG['parent'] : '';
$menu = Eleanor::$Cache->Get('left_menu'. Language::$main . $parent);
if($menu === false) {
    global$Eleanor;
	$p = $menu = '';
	if($parent) {
		$first_r = Eleanor::$Db->Query('SELECT `title` FROM `'. P .'menu` INNER JOIN `'. P .'menu_l` USING(`id`) WHERE `id` = '. $parent .' AND `language` IN("", "'. Language::$main .'") LIMIT 1');
		$first = $first_r->fetch_assoc();
		$p .= $parent. ',';
        $menu_item = '<div id="left_menu_title" class="document_body_menu_title">'. $first['title'] .'</div><div id="left_menu_shadow" class="document_body_menu_title_shadow"></div>';
	} else {
        $menu_item = '';
    }
    $r = Eleanor::$Db->Query('SELECT `id` FROM `'. P .'menu` INNER JOIN `'. P .'menu_l` USING(`id`) WHERE `language` IN("","'. Language::$main .'") AND `status`=1 AND `parents` = "'. $p .'" AND `title` = "'. $Eleanor->module['section'] .'" LIMIT 1');
    if ($r->num_rows !== 0) {
        $parent2 = $r->fetch_assoc();
        $p .= $parent2['id'] . ',';
    } else {
        $r = Eleanor::$Db->Query('SELECT `id` FROM `'. P .'menu` INNER JOIN `'. P .'menu_l` USING(`id`) WHERE `language` IN("","'. Language::$main .'") AND `status`=1 AND `parents` = "'. $p .'" AND `title` = "default" LIMIT 1');
        $parent2 = $r->fetch_assoc();
        $p .= $parent2['id'] . ',';
    }
    $r->free();
	$r = Eleanor::$Db->Query('SELECT `id`, `title` FROM `'. P .'menu` INNER JOIN `'. P .'menu_l` USING(`id`) WHERE `language` IN("","'. Language::$main .'") AND `status`=1 AND `parents` = "'. $p .'" ORDER BY `parents` ASC, `pos` ASC');
	while($col_t = $r->fetch_assoc()) {
		$menu_item .= '<ul>
		<li class="document_body_left_navigation_title">'. $col_t['title'] .'</li>';

		$col = Eleanor::$Db->Query('SELECT `id`, `title`, `url`, `eval_url` FROM `'. P .'menu` INNER JOIN `'. P .'menu_l` USING(`id`) WHERE `language` IN("", "'. Language::$main .'") AND `status` = 1 AND `parents` = "'. $p . $col_t['id'] .'," ORDER BY `parents` ASC, `pos` ASC');
		while($a = $col->fetch_assoc()) {
			if($a['eval_url']) {
				ob_start();
				$f = create_function('$Eleanor', $a['eval_url']);
				if($f === false) {
					ob_end_clean();
					continue;
				}
				ob_end_clean();
				$url = $f($GLOBALS['Eleanor']);
			} else {
				$url = $a['url'];
			}
			$menu_item .= '<li><span><a href="'. $url .'" title="'. $a['title'] .'">'. $a['title'] .'</a></span></li>';
		}
		$menu_item .=  '<li class="document_body_left_navigation_border"></li></ul>';
	}
	$menu = $menu_item;
	Eleanor::$Cache->Put('left_menu'. Language::$main . $parent, $menu);
}
return $menu;
